package io.vertx.guides.wiki.database;

import io.vertx.codegen.annotations.Fluent;
import io.vertx.codegen.annotations.ProxyGen;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.jdbc.JDBCClient;

import java.util.HashMap;


/**
 * Created by zhangwei on 2017/7/19.
 */

@ProxyGen
interface WikiDatabaseService {
    @Fluent
    fun fetchAllPages(resultHandler: Handler<AsyncResult<JsonArray>>): WikiDatabaseService

    @Fluent
    fun fetchPage(name: String, resultHandler: Handler<AsyncResult<JsonObject>>): WikiDatabaseService

    @Fluent
    fun createPage(title: String, markdown: String, resultHandler: Handler<AsyncResult<Void>>): WikiDatabaseService

    @Fluent
    fun savePage(id: Int, markdown: String, resultHandler: Handler<AsyncResult<Void>>): WikiDatabaseService

    @Fluent
    fun deletePage(id: Int, resultHandler: Handler<AsyncResult<Void>>): WikiDatabaseService


    companion object {
        fun create(dbClient: JDBCClient, sqlQueries: MutableMap<SqlQuery, String>, resultHandler: Handler<AsyncResult<WikiDatabaseService>>): WikiDatabaseService {
            return WikiDatabaseServiceImpl(dbClient, sqlQueries, resultHandler)
        }

//        fun createProxy(vertx: Vertx, address: String): WikiDatabaseService {
//            return WikiDatabaseServiceVertxEBProxy(vertx, address)
//        }
    }
}